package com.telit.firecommand.service.impl;


import com.telit.common.util.TimeUtils;
import com.telit.firecommand.dto.*;
import com.telit.firecommand.entity.CommFireAlarm;
import com.telit.firecommand.service.FireDisposeService;
import com.telit.upms.vo.UserListByPageVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Auther zhouyu
 * @description 火情处置接口实现类
 **/
@Service
@Transactional(rollbackFor = Exception.class)
public class FireDisposeServiceImpl extends FireDisposeService {


    /**
     * 生成消息处置意见
     * @param recordScene
     * @return
     */
    @Override
    public String generateDisposeInfo(RecordScene recordScene) {
        if (recordScene instanceof TelephoneAlarm){
            return "防火管理员添加电话接警记录";
        }else if (recordScene instanceof AddFireByWebAdmin){
            return "防火管理员添加火情";
        }else if (recordScene instanceof AddEmergencyDrillByWebAdmin){
            return "防火管理员添加应急演练";
        }else if (recordScene instanceof ReceiveAlarm){
            return "火情接警";
        }else if (recordScene instanceof SetRepeatFire){
            SetRepeatFire setRepeatFire = (SetRepeatFire) recordScene;
            CommFireAlarm commFireAlarm = setRepeatFire.getCommFireAlarm();
            return "将火情设为重复火情，重复火情信息：\"" + TimeUtils.convertStringTime(commFireAlarm.getFindTime()) + "," +
                    getResourceName(commFireAlarm.getResource()) + commFireAlarm.getSourceName() + "上报的" +
                    commFireAlarm.getDistrictName() + "的火情\"";
        }else if (recordScene instanceof IssueFireVerificationTask){
            IssueFireVerificationTask issueFireVerificationTask = (IssueFireVerificationTask)recordScene;
            return "下发火情核实任务，执行人："+issueFireVerificationTask.getExecutePerson().toString();
        }else if (recordScene instanceof ConfirmRealFire){
            return "确认火情为真实火情";
        }else if (recordScene instanceof ConfirmFakeFire){
            ConfirmFakeFire confirmFakeFire = (ConfirmFakeFire) recordScene;
            return "确认火情为误报火情，误报说明：\""+confirmFakeFire.getFakeDesc()+"\"";
        }else if (recordScene instanceof SetEmergencyDrill){
            return "确认火情为应急演练火情";
        }else if (recordScene instanceof PushFireMsg){
            PushFireMsg pushFireMsg = (PushFireMsg) recordScene;
            List<UserListByPageVo> foresterDTOList = pushFireMsg.getForesterDTOList();
            StringBuilder stringBuilder = new StringBuilder("推送至\"");
            foresterDTOList.forEach(e->{
                stringBuilder.append(e.getOrganizationCn()).append("的").append(e.getRealName()).append(",");
            });
            return stringBuilder.substring(0,stringBuilder.length()-1)+"\"";
        }else if (recordScene instanceof ProcessFire){
            return "开始火情处置";
        }else if (recordScene instanceof FinishDispose){
            return "完成火情处置";
        }else if (recordScene instanceof FirePositionCorrection){
            return "修改火情位置，原经纬度："+((FirePositionCorrection) recordScene).getOldlongitude()+","+((FirePositionCorrection) recordScene).getOldlatitude();
        }
        return "";
    }

    /**
     * 获取火情来源
     * @param resource
     * @return
     */
    private String getResourceName(String resource){
        if ("1".equals(resource)){
            return "护林员";
        }else if ("2".equals(resource)){
            return "飞手";
        }else if ("3".equals(resource)){
            return "视频监控";
        }else if ("4".equals(resource)){
            return "卫星";
        }else if ("5".equals(resource)){
            return "无人机";
        }else if ("6".equals(resource)){
            return "电话接警";
        }else if ("7".equals(resource)){
            return "防火管理员";
        }else if ("8".equals(resource)){
            return "视频监控";
        }else if ("9".equals(resource)){
            return "视频监控";
        }else {
            return "未知来源";
        }
    }
}
